<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.*, java.text.*" %>
<%@ page import="com.google.appengine.api.users.*" %>
<%@ page import="com.google.appengine.api.datastore.*" %>     
<%
	int projectId = request.getParameter("projectId")==null?0:Integer.parseInt(request.getParameter("projectId"));	//프로젝트 ID	
	int issueId = request.getParameter("issueId")==null?0:Integer.parseInt(request.getParameter("issueId"));		//이슈 ID

    String issueSj = "";
    User frstRegisterUser = null;
    String issueCn = "";
    
   	UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    
 	//로그인 사용자만 접근
    if( user == null ) {
    	out.print("<script>");
		out.print("alert('접근 권한이 없습니다.');");
		out.print("history.back();");
		out.print("</script>");
		
		return;
    }
    
    if( issueId > 0 ) {
    	
	    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
		Key issueKey = KeyFactory.createKey(KeyFactory.createKey("issue", projectId), "issue", issueId);
		
		Entity issue = datastore.get(issueKey);	
		issueSj = (String) issue.getProperty("issueSj");
		frstRegisterUser = (User)issue.getProperty("frstRegisterUser");
		issueCn = (String) issue.getProperty("issueCn");
		
		if(user.equals(frstRegisterUser)==false) {
			out.print("<script>");
			out.print("alert('접근 권한이 없습니다.');");
			out.print("history.back();");
			out.print("</script>");
			
			return;
		}
    }
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>이슈 등록</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="X-UA-Compatible" content="chrome=1">
	<link href="http://www.gstatic.com/codesite/ph/17444577587916266307/css/ph_core.css" rel="stylesheet" type="text/css" />
	<link href="http://code.google.com/css/codesite.pack.04102009.css" rel="stylesheet" type="text/css" />
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
	<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.0/jquery-ui.min.js"></script>
</head>
<body>

	<!-- content -->
	<div id="gc-pagecontent">
		<h1 class="page_title">신재생 에너지 코리아</h1>

		<!-- tabs -->
		<div id="tabs" class="gtb">
			<a href="#" class="tab">Home</a> 
			<a href="#" class="tab active">이슈 관리</a> 
			<a href="#" class="tab">Product</a> 
			<a href="#" class="tab">Item</a> 
			<a href="#" class="tab">Order</a>
			<div class="gtbc"></div>
		</div>
		<!-- home page content -->
		<div class="g-unit">
			<!-- search container -->
		   	<div class="create-ctr">
			   	<!-- section title -->
			   	<h2>이슈 목록</h2>
			   	<form name="issueForm" action="issueInsert.jsp" method="post">
			   		<input type="hidden" name="projectId" value="<%=projectId%>">
					<input type="hidden" name="issueId" value="<%=issueId%>">		
				  	<table width="200" cellspacing="0" cellpadding="0">
			           <tr> 
			           	 <td><label for="issueSj">제목</label></td>
			             <td><input type="text" name="issueSj" id="issueSj" size="70" maxlength="1000" value="<%=issueSj%>" style="width: 185px;" autocomplete="off" class="gsc-input"/>
			           </tr>
			           <tr>
			             <td><label for="issueCn">내용</label></td>
			             <td>
			             	<textarea name="issueCn" id="issueCn" rows="10" cols="70" style="width: 185px;" autocomplete="off" class="gsc-input" maxlength="2048" ><%=issueCn%></textarea>
						</td>
			           </tr>
			            <tr>
			              <td>&nbsp;</td>
			              <td> 
			                  <input type="submit" class="save" value="저장" />
			                  <input type="button" class="cancel" title="Cancel" value="취소" onclick="location.href='issueList.jsp?projectId=<%=projectId%>'" />
			                  <input type="reset" id="item-reset" class="cancel" title="Reset" value="Reset" style="visibility: hidden"/>
			              </td>
			            </tr>
					 </table>
				</form>
		  	</div>
	   	</div>
	</div>

</body>
</html>